Skip to content

gh-142927: Show module names instead of file paths in flamegraph#146040

Open
ivonastojanovic wants to merge 4 commits intopython:mainfrom
ivonastojanovic:flamegraph_modules
Open

gh-142927: Show module names instead of file paths in flamegraph#146040
ivonastojanovic wants to merge 4 commits intopython:mainfrom
ivonastojanovic:flamegraph_modules

Conversation

@ivonastojanovic
Copy link
Copy Markdown
Contributor

@ivonastojanovic ivonastojanovic commented Mar 16, 2026

Display module names instead of full file paths (/home/user/project/pkg/mod.pypkg.mod) in flamegraph for readability.

image

CC: @pablogsal @lkollar

The issue:

Show module names instead of full file paths — /home/user/project/pkg/mod.py → pkg.mod for readability

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Mar 17, 2026

As I am on mobile it is hard to review but is it possible to have an option to keep showing full paths? this may help if we want to open the file in an IDE. Or does this change only affect the flamegraph output?

Alternative: show the full path of the selected cell as a footer

@ivonastojanovic
Copy link
Copy Markdown
Contributor Author

As I am on mobile it is hard to review but is it possible to have an option to keep showing full paths? this may help if we want to open the file in an IDE. Or does this change only affect the flamegraph output?

Alternative: show the full path of the selected cell as a footer

@picnixz That’s a great idea. I’ve added a toggle that lets users switch between full paths and module names. Toggling it updates both the flamegraph frames and the hover tooltips. This change only affects the flamegraph output. Let me know what you think of the toggle.

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Mar 20, 2026

Toggling was one solution I had in mind so it is fine! showing full path without toggling as a small footer with a "copy path" if you were to double click the footer would also be an alternative/follow-up improvement.

Otherwise just toggling is great! thanks!

Move module name extraction logic from heatmap_collector to shared
module_utils to enable flamegraph to display module names instead of
full file paths.
Display module names instead of full file paths
(/home/user/project/pkg/mod.py → pkg.mod) in flamegraph for
readability.
Users can now switch between module names and file paths using the
toggle in the View Mode sidebar. Module names are concise, while
file paths help locate the exact source file, both are useful
depending on the debugging context.
Copy link
Copy Markdown
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments

continue

# Fallback: just use the filename
return (_path_to_module(file_path), 'other')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_path_to_module called with an absolute path produces /.home.user.project.main because Path("/home/user/project/main").parts returns ("/", "home", "user", "project", "main") and the root separator gets joined in. Same issue on Windows with the drive letter.

return (str(filename), 'other')

# Check if it's in stdlib
if path_info['stdlib'] and _is_subpath(file_path, path_info['stdlib']):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_is_subpath calls relative_to() to check containment, then the caller immediately calls relative_to() again to get the relative path. Could be a single try/except block. Also Path.is_relative_to() is available since 3.9.


child_entry = {
"name": name_idx,
"label": label_idx,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Child nodes get a label field here but root nodes (promoted root and multi-root fallback) never get one. The JS fallback chain masks this but the root shows in full-path format even in module-name mode.

if (useModuleNames) {
return moduleName || filename;
}
return filename ? filename.split('/').pop() : filename;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toggle is labeled "Full Paths" but this returns filename.split("/").pop() which is the basename. Also the tooltip builds displayName differently (using the full filename), so different parts of the UI disagree on what to show.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants